*** REPLICATION TOOLKIT ***

* AUTHORS: CIMINELLI DUVAL FURCERI 

* ARTICLE: EMPLOYMENT PROTECTION DEREGULATION AND LABOR SHARES IN ADVANCED ECONOMIES 

* JOURNAL: REVIEW OF ECONOMICS AND STATISTICS

* OUTPUT: TABLE E1 (ONLINE APPENDIX)

***************************

cd ""

use "DTA files/Dataset", clear

putexcel set "Tables/E1", modify

**************** REVERSE CAUSALITY TEST *******************

*** Country level

xtset id_cross_section year

egen va_country = sum(va) if va != ., by(year ifscode)
egen lab_country = sum(lab) if lab != ., by(year ifscode)
gen a_country1 = (lab_country/va_country)
egen a_country = mean(a_country1), by(year ifscode)

gen x = d.a_country 
replace x = . if id_industry != 1
gen EPLregularworkers_p = EPLregularworkers
replace EPLregularworkers_p = 0 if EPLregularworkers < 0 & EPLregularworkers != . 
gen EPLregularworkers_n = EPLregularworkers
replace EPLregularworkers_n = 0 if EPLregularworkers > 0 & EPLregularworkers != .
replace EPLregularworkers_n = 1 if EPLregularworkers_n == -1
gen EPLregularworkers_s = EPLregularworkers
replace EPLregularworkers_s = 1 if EPLregularworkers == -1

reg EPLregularworkers x l1.x l2.x l3.x l4.x i.year i.id_country, cluster(id_country)
	test x = l1.x = l2.x = l3.x = l4.x = 0
	local pval11 = r(p)

reg EPLregularworkers_p x l1.x l2.x l3.x l4.x i.year i.id_country, cluster(id_country)
	test x = l1.x = l2.x = l3.x = l4.x = 0
	local pval12 = r(p)
	
reg EPLregularworkers_n x l1.x l2.x l3.x l4.x i.year i.id_country, cluster(id_country)
	test x = l1.x = l2.x = l3.x = l4.x = 0
	local pval13 = r(p)
	

*** Country-industry => industry in upper half of layoff rate
use "DTA files/Dataset", clear

sum layoff_rate, detail
local p50 = r(p50)
gen Y = 100*EPLregularworkers
drop if layoff_rate < `p50' 
drop if layoff_rate == .
gen Y_p = Y 
gen Y_n = Y 
replace Y_p = 0 if Y == -100
replace Y_n = 0 if Y == 100
replace Y_n = -Y_n if Y_n < 0

xtset id_cross_section year
gen x_emp = 100*(EMP-l.EMP)/(l.EMP)
gen prod = VA_QI/EMP
gen x_lprod = 100*(prod-l.prod)/(l.prod)
gen x_va = 100*(va-l.va)/(l.va)
gen a = 100*lab/va
gen x_ls = d.a
gen x_tfp = 100*(TFPva_I-l.TFPva_I)/(l.TFPva_I)

reg Y x_ls l1.x_ls l2.x_ls l3.x_ls l4.x_ls i.id_cross_section, cluster(id_country_year)
	test x_ls = l1.x_ls = l2.x_ls = l3.x_ls = l4.x_ls = 0
	local pval21 = r(p)
	
reg Y_p x_ls l1.x_ls l2.x_ls l3.x_ls l4.x_ls i.id_cross_section, cluster(id_country_year)
	test x_ls = l1.x_ls = l2.x_ls = l3.x_ls = l4.x_ls = 0
	local pval22 = r(p)
	
reg Y_n x_ls l1.x_ls l2.x_ls l3.x_ls l4.x_ls i.id_cross_section, cluster(id_country_year)
	test x_ls = l1.x_ls = l2.x_ls = l3.x_ls = l4.x_ls = 0
	local pval23 = r(p)

*** Country-industry => industry in bottom half of EOS
use "DTA files/Dataset", clear

sum EOS_serv4_OLS, detail
local p50 = r(p50)
gen Y = 100*EPLregularworkers
drop if EOS_serv4_OLS > `p50' 
drop if EOS_serv4_OLS == .
gen Y_p = Y 
gen Y_n = Y 
replace Y_p = 0 if Y == -100
replace Y_n = 0 if Y == 100
replace Y_n = -Y_n if Y_n < 0

xtset id_cross_section year
gen x_emp = 100*(EMP-l.EMP)/(l.EMP)
gen prod = VA_QI/EMP
gen x_lprod = 100*(prod-l.prod)/(l.prod)
gen x_va = 100*(va-l.va)/(l.va)
gen a = 100*lab/va
gen x_ls = d.a
gen x_tfp = 100*(TFPva_I-l.TFPva_I)/(l.TFPva_I)

reg Y x_ls l1.x_ls l2.x_ls l3.x_ls l4.x_ls i.id_cross_section, cluster(id_country_year)
	test x_ls = l1.x_ls = l2.x_ls = l3.x_ls = l4.x_ls = 0
	local pval31 = r(p)
	
reg Y_p x_ls l1.x_ls l2.x_ls l3.x_ls l4.x_ls i.id_cross_section, cluster(id_country_year)
	test x_ls = l1.x_ls = l2.x_ls = l3.x_ls = l4.x_ls = 0
	local pval32 = r(p)
	
reg Y_n x_ls l1.x_ls l2.x_ls l3.x_ls l4.x_ls i.id_cross_section, cluster(id_country_year)
	test x_ls = l1.x_ls = l2.x_ls = l3.x_ls = l4.x_ls = 0
	local pval33 = r(p)
	
	
*** Save

mat mat = J(3,3,.)
forvalues i = 1 / 3 {
forvalues j = 1 / 3 {
mat mat[`i',`j'] =`pval`i'`j''
}
}
putexcel B2=matrix(mat) 

